import 'package:flutter/material.dart';
import 'package:ruitmentapp/core/extension/int_extension.dart';
import 'package:ruitmentapp/personnel/model/zj_home_model.dart';
import 'package:ruitmentapp/core/shared/size_fit.dart';
import 'package:ruitmentapp/personnel/model/zj_job_details_model.dart';

final cardRadius = 5.px;

class ZJHomeContentCompanyDetailsCard extends StatelessWidget {

  final ZJJobDetailsModel _detailsModel;
  ZJHomeContentCompanyDetailsCard(this._detailsModel);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: buildTitleCard(context),
    );
  }

  Widget buildTitleCard(BuildContext context) {
    return Card(
      margin: EdgeInsets.only(left: 20.px, right: 20.px, bottom: 10.px),
      elevation: 0.0,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(cardRadius)),
      child: Column(
        children: <Widget>[
          buildPushTitleInfo(context),
          buildLineInfo(),
          buildBasicInfo(context),
          buildOperationInfo(context),
        ],
      ),
    );
  }

  Widget buildLineInfo() {
    return SizedBox(
        width: ZJSizeFit.screenWidth - 70.px,
        height: 1.px,
        child: Container(
          color: const Color(0xFFF3F5F7),
        )
    );
  }

  Widget buildPushTitleInfo(BuildContext context) {
    return Row(
      children: const [
        Expanded(child:
        Padding(
          padding: EdgeInsets.only(top: 10, left: 15, right: 15,bottom: 10),
          child: Text('公司信息',
              textAlign:TextAlign.left,
              style: TextStyle(
                  color: Color(0xFF3F4756),
                  fontSize: 16,
                  fontWeight: FontWeight.bold)
          ),
        ),
        ),
      ],
    );
  }

  Widget buildBasicInfo(BuildContext context) {

    List <String> stringArray = _detailsModel.publishDetail.treatment.split(',');
    List <Widget> textArray = [];
    for(String item in stringArray){
      textArray.add(
          Card(
            elevation: 0.0,//设置阴影，即card在z轴的距离，数字越大阴影越重
            color: const Color(0xFFF3F5F7),//设置颜色，数字为颜色饱和度
            shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(3.0))),
            child: Container(
                padding: const EdgeInsets.only(left: 10, top: 3, bottom: 3, right: 10),
                child: Text(item, style: const TextStyle(color: Color(0xFF77809E),fontSize: 12))
            ),
          )
      );
    }

    return _detailsModel.publishDetail.treatment.isNotEmpty ? Container(
      color: Colors.white,
      width: MediaQuery.of(context).size.width - 70,
      height: 40,
      margin: const EdgeInsets.only(top: 5),
      child: SingleChildScrollView(
        physics: const BouncingScrollPhysics(),
        scrollDirection: Axis.horizontal,
        child: Center(
          child: Row(
            children: textArray,
          ),
        ),
      ),
    ):Container();
  }

  Widget buildOperationInfo(BuildContext context) {
    String url = _detailsModel.publishDetail.logo ??
        "https://prod.avatars.img.hr100.xin/2021-07/C9C34923CACE4854B07E5B938B215BD6.jpg";
    url = url.contains('http')
        ? url
        : "https://prod.avatars.img.hr100.xin/2021-07/C9C34923CACE4854B07E5B938B215BD6.jpg";

    String title = '${
        _detailsModel.publishDetail.companyCityName
    } · ${_detailsModel.publishDetail.natureOfBusinessName
    } · ${_detailsModel.publishDetail.numberName
    } · ${_detailsModel.publishDetail.industry}';

    return Row(
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.only(left: 15, bottom: 15,top:10),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(22.px),
              child: Image.network(
                url,
                width: 45.px,
                height: 45.px,
              ),
            ),
          ),
          Expanded(child:
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                padding: const EdgeInsets.only(left: 10),
                child: Text(_detailsModel.publishDetail.companyName,
                    style: const TextStyle(color: Color(0xFF3F4756), fontSize: 14)),
              ),
              Padding(
                padding: const EdgeInsets.only(left: 10,top: 5),
                child: Text(title,
                    style: const TextStyle(color: Color(0xFF77809E), fontSize: 11)),
              ),
            ],
          )
          ),
        ]
    );
  }
}
